<?php
/**
 * Created by PhpStorm.
 * User: xueb
 * Date: 2016/12/20
 * Time: 上午11:36
 */

namespace App\Components;


class HttpRequestResult
{
    protected $_head = null;
    protected $_content = null;
    protected $_statusCode = 200;

    public function __construct(array $map_Result){
        $this->_head = isset($map_Result['head']) ? $map_Result['head'] : null;
        $this->_content = isset($map_Result['content']) ? json_decode($map_Result['content'],false) : null;
    }

    public function data(string $name){
        return isset($this->_content['data']) && isset($this->_content['data'][$name]) ?
            $this->_content['data'][$name] : null;
    }

    public function __get(string $name){
        if($name == 'statusCode'){
            return $this->_statusCode;
        }
        if($name == 'code'){
            return $this->_content['code'];
        }
        if($name == 'success'){
            return $this->code == 1;
        }

        return $this->data($name);
    }

}